public class test {
    public int maxProfit(int[] prices) {
        int ret = 0;
        for(int i = 0;i < prices.length;i++){
            int mid = prices[i];
            while(i < prices.length - 1 && prices[i] < prices[i + 1]){
                i++;
            }
            ret += prices[i] - mid;
        }
        return ret;
    }
}